package demo1;

import java.util.*;

/**
 * @Author liangzai
 * @Description:
 */
public class Test {
    //只出现一次的数字
    public int[] singleNumber(int[] nums) {
        if (nums.length <= 1) {
            return nums;
        }
        Arrays.sort(nums);
        int[] array = new int[nums.length];
        int count = 0;
        for (int i = 0; i < nums.length; i++) {
            if (i == 0) {
                if(nums[i]!=nums[i+1]){
                    array[count++] = nums[i];
                }
            }
            if (i == nums.length - 1) {
                if(nums[i]!=nums[i-1]){
                    array[count++] = nums[i];
                }
            }
            if(nums[i]!=nums[i+1] && nums[i]!=nums[i-1]){
                array[count++] = nums[i];
            }
        }
        return Arrays.copyOf(array,count-1);
    }

    public static void main1(String[] args) {
        String s = "lisajldfs";
        System.out.println(s.substring(1,2));
    }

    //串联所有单词的字串
    public List<Integer> findSubstring(String s, String[] words) {
        Map<String,Integer> map1 = new HashMap<String,Integer>();
        //Map<String,Integer> map2 = new HashMap<String,Integer>();
        List<Integer> list = new ArrayList<>();
        for(String each : words){
            map1.put(each,map1.getOrDefault(each,0)+1);
        }
        int n = words[0].length(); int len = words.length;
        for (int i = 0; i < n; i++) {
            Map<String,Integer> map2 = new HashMap<String,Integer>();
            for(int left=i,right=i,count=0;right+n<=s.length();right+=n){
                String in = s.substring(right,right+n);
                map2.put(in, map2.getOrDefault(in, 0) + 1);
                if(map2.get(in)<=map1.getOrDefault(in,0)){
                    count++;
                }
                if (right - left + 1 > len * n) {
                    String out = s.substring(left,left+n);
                    if(map2.get(out)<=map1.getOrDefault(out,0)){
                        count--;
                    }
                    map2.put(out, map2.getOrDefault(out, 0) - 1);
                    left+=n;
                }
                if (count == len) {
                    list.add(left);
                }
            }
        }
        return list;
    }

    //构成整数的下标对数目
    public int countCompleteDayPairs(int[] hours) {
        int count = 0;
        for (int i = 0; i < hours.length; i++) {
            for (int j = i+1; j < hours.length; j++) {
                if (hours[i] + hours[j] % 24 == 0) {
                    count++;
                }
            }
        }
        return count;
    }
}
